package mlz.b_buffered;

import com.sun.source.tree.NewArrayTree;
import org.junit.Test;

import java.io.*;

/*
转换流
 */
public class InputStreamReaderDemo01 {
    @Test
    public void test01() throws IOException {
        //系统默认字符集是utf-8
        //手动修改了文件的字符集为GBK,但是在读取的时候用了UTF-8的字符集进行读取
        InputStreamReader isr = new InputStreamReader(
                new FileInputStream("writer1.txt"),"GBK");

        BufferedReader br = new BufferedReader(isr);

        String line;
        while((line = br.readLine()) != null){
            System.out.println(line);
        }
//        int line;
//        while((line = isr.read()) != -1){
//            System.out.println(line);
//        }
    }


    @Test
    public void test02() throws IOException {
        OutputStreamWriter osw =
                new OutputStreamWriter(
                        new FileOutputStream("writer1.txt",true),"GBK");
        BufferedWriter bw = new BufferedWriter(osw);

        bw.newLine();
        bw.write("我是中国人!!");

        //刷新缓冲区
        bw.flush();
    }
}








